package com.tkjt.pms.calc.common;

import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Set;

public class NodeDepenChains {

	//KEY1: 数据项编码； Value：该数据项所在节点的上级层级树
	private Map<String, Map<Integer, Set<String>>> indexValueDepenChains = new HashMap<String, Map<Integer, Set<String>>>();

	public void addOneDepenChain(String indexValueCode, LinkedList<String> depenList) {
		Map<Integer, Set<String>> tempMap = indexValueDepenChains.get(indexValueCode);
		if (null == tempMap) {
			tempMap = new HashMap<Integer, Set<String>>();
			indexValueDepenChains.put(indexValueCode, tempMap);
		}
		for(int index=0;index<depenList.size();index++) {
			Set<String> tempSet = tempMap.get(Integer.valueOf(index+1));
			if(null==tempSet) {
				tempSet = new HashSet<String>();
				tempMap.put(Integer.valueOf(index+1), tempSet);
			}
			tempSet.add(depenList.get(index));
		}
	}

	public boolean hasDepenChain(String indexValueCode) {
		return indexValueDepenChains.containsKey(indexValueCode);
	}

	public Integer getDepenChainLevel(String indexValueCode) {
		return indexValueDepenChains.get(indexValueCode).size();
	}

	public Set<String> getDepenChainLevelCodes(String indexValueCode, Integer depenLevel) {
		if(null == indexValueDepenChains.get(indexValueCode)) {
			return new HashSet<String>();
		}
		Set<String> tempSet = indexValueDepenChains.get(indexValueCode).get(depenLevel);
		if (null == tempSet) {
			return new HashSet<String>();
		}
		return tempSet;
	}

	public void removeDepenChain(String indexValueCode) {
		indexValueDepenChains.remove(indexValueCode);
	}

}
